package cn.sfa.common.utils;

import java.util.regex.Pattern;

public class FormValidate {
	/**
	  * 判断字符是否是数字组成【0-9】
	  *  
	  * @return boolean
	  * @param number
	  *  
	  * @author guoqiang <guoqiang@bestwiz.cn>
	  */
	  public static boolean isNumber(String number) {

	  int count = 0;
	  for (int i = 0; i < number.length(); i++) {
	  if (String.valueOf(number.charAt(i)).matches("\\d"))
	  count++;
	  }
	  if (count == number.length())
	  return true;
	  else
	  return false;
	  }

	  /**
	  * 判断字符是否是字母
	  *  
	  * @return boolean
	  * @param en
	  *  
	  * @author guoqiang <guoqiang@bestwiz.cn>
	  */
	  public static boolean isEn(String en) {

	  int count = 0;
	  for (int i = 0; i < en.length(); i++) {
	  if (String.valueOf(en.charAt(i)).matches("[a-zA-Z]"))
	  count++;
	  }
	  if (count == en.length())
	  return true;
	  else
	  return false;
	  }

	  /**
	  * 判断字符是否是IP地址
	  *  
	  * @return boolean
	  * @param ip
	  *  
	  * @author guoqiang <guoqiang@bestwiz.cn>
	  */
	  public static boolean isIp(String ip) {

	  return ip.matches("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
	  }

	  /**
	  * 判断字符是否是E-Mail地址
	  *  
	  * @return boolean
	  * @param mail
	  *  
	  * @author guoqiang <guoqiang@bestwiz.cn>
	  */
	  public static boolean isMail(String mail) {

	  return mail.matches("[a-zA-Z0-9|_|-]{3,}@[a-zA-Z0-9]{1,}\\.[a-zA-Z0-9]{2,}");
	  }

	  /**
	  * 判断字符是否是正确的日期格式（不包括时间）
	  *  
	  * @return boolean
	  * @param date
	  *  
	  * @author guoqiang <guoqiang@bestwiz.cn>
	  */
	  public static boolean isDate(String date) {

	  return date
	  .matches("^((((1[6-9]|[2-9]\\d)\\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\\d|3[01]))|(((1[6-9]|[2-9]\\d)\\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\\d|30))|(((1[6-9]|[2-9]\\d)\\d{2})-0?2-(0?[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29))$");
	  }

	  
	  /**
		  * 判断字符是否是正确的日期格式（包括时间）
		  *  
		  * @return boolean
		  * @param time
		  *  
		  * @author guoqiang <guoqiang@bestwiz.cn>
		  */
		  public static boolean isTime(String time) {

		  return time
		  .matches("^((((1[6-9]|[2-9]\\d)\\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\\d|3[01]))|(((1[6-9]|[2-9]\\d)\\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\\d|30))|(((1[6-9]|[2-9]\\d)\\d{2})-0?2-(0?[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29)) (20|21|22|23|[0-1]?\\d):[0-5]?\\d:[0-5]?\\d$");
		  }
		  

		  /**
		  * 匹配帐号是否合法(字母开头，允许5-16字节，允许字母数字下划线)
		  *  
		  * @return boolean
		  * @param time
		  *  
		  * @author guoqiang <guoqiang@bestwiz.cn>
		  */
		  public static boolean siUserName(String username) {

		  return username
		  .matches("^[a-zA-Z][a-zA-Z0-9_]$");
		  }
		  
		  /**
			  * 判断字符是否URL
			  *  
			  * @return boolean
			  * @param time
			  *  
			  * @author guoqiang <guoqiang@bestwiz.cn>
			  */
			  public static boolean isURL(String url) {

			  return url
			  .matches("[a-zA-z]+://[^\\s]*");
			  }
			  
			  /**
				  * 匹配国内电话号码如 0511-4405222 或 021-87888822
				  *  
				  * @return boolean
				  * @param time
				  *  
				  * @author guoqiang <guoqiang@bestwiz.cn>
				  */
				  public static boolean isPhoneNumber(String phonenumber) {

				  return phonenumber
				  .matches("\\d{3}-\\d{8}|\\d{4}-\\d{7}");
				  }
				  
				  
				  /**
					  * 匹配腾讯QQ号：腾讯QQ号从10000开始
					  *  
					  * @return boolean
					  * @param time
					  *  
					  * @author guoqiang <guoqiang@bestwiz.cn>
					  */
					  public static boolean isQQ(String qq) {

					  return qq
					  .matches("[1-9][0-9]{4,}");
					  }
					  
					  
					  
					  /**
						  * 匹配中国邮政编码:中国邮政编码为6位数字
						  *  
						  * @return boolean
						  * @param time
						  *  
						  * @author guoqiang <guoqiang@bestwiz.cn>
						  */
						  public static boolean isMailCode(String mailCode) {

						  return mailCode
						  .matches("[1-9]\\d{5}(?!\\d)\\");
						  }
						  
						  
						  /**
							  * 匹配手机号码：忽略前面0之后判断它是11位的。 
							  *  
							  * @return boolean
							  * @param time
							  *  
							  * @author guoqiang <guoqiang@bestwiz.cn>
							  */
							  public static boolean isMobileNumber(String mobileNumber) {

							  return mobileNumber
							  .matches("^(13[0-9]|15[0|3|6|7|8|9]|18[3|6|7|8|9])\\d{8}$");
							  }
							  
							  
							  /**
								  * 匹配身份证：中国的身份证为15位或18位 
								  *  
								  * @return boolean
								  * @param time
								  *  
								  * @author guoqiang <guoqiang@bestwiz.cn>
								  */
								  public static boolean isIDCard(String idCard) {

								  return idCard
								  .matches("\\d{15}|\\d{18}");
								  }
								  
								  
								  /**
									  * ^[A-Za-z]+$　　//匹配由26个英文字母组成的字符串
									  *  
									  * @return boolean
									  * @param time
									  *  
									  * @author guoqiang <guoqiang@bestwiz.cn>
									  */
									  public static boolean isZhiMu(String zhimu) {

									  return zhimu
									  .matches("^[A-Za-z]+$");
									  }
									  
									  /**
										  *^[A-Z]+$　　匹配由26个英文字母的大写组成的字符串
										  *  
										  * @return boolean
										  * @param time
										  *  
										  * @author guoqiang <guoqiang@bestwiz.cn>
										  */
										  public static boolean isDaXie(String daXie) {

										  return daXie
										  .matches("^[A-Z]+$");
										  }
										  
										  /**
											  * ^[a-z]+$　　//匹配由26个英文字母的小写组成的字符串
											  *  
											  * @return boolean
											  * @param time
											  *  
											  * @author guoqiang <guoqiang@bestwiz.cn>
											  */
											  public static boolean isXiaoXie(String xiaoXie) {

											  return xiaoXie
											  .matches("^[a-z]+$");
											  }
											  
											  /**
												  * ^[A-Za-z0-9]+$　　//匹配由数字和26个英文字母组成的字符串
												  *  
												  * @return boolean
												  * @param time
												  *  
												  * @author guoqiang <guoqiang@bestwiz.cn>
												  */
												  public static boolean isNuberAndZhiMu(String str) {

												  return str
												  .matches("^[A-Za-z0-9]+$");
												  }
												  
												  
												  /**
													  * ^\w+$　　//匹配由数字、26个英文字母或者下划线组成的字符串
													  *  
													  * @return boolean
													  * @param time
													  *  
													  * @author guoqiang <guoqiang@bestwiz.cn>
													  */
													  public static boolean isNumberZhiMu_(String str) {

													  return str
													  .matches("^\\w+$");
													  }
													  
													  /**
														  * 匹配ip地址：\d+\.\d+\.\d+\.\d+
														  *  
														  * @return boolean
														  * @param time
														  *  
														  * @author guoqiang <guoqiang@bestwiz.cn>
														  */
														  public static boolean isIpAddress(String ip) {

														  return ip
														  .matches("\\d+\\.\\d+\\.\\d+\\.\\d+");
														  }
					/**
					 * 中文字符的正则表达式：
					 * @param str
					 * @return
					 */
					public static boolean isChinese(String str)
					{
						return str.matches("^[\u4e00-\u9fa5]+$");
					}
					
					public static boolean isUsername(String username)
					{
						return username.matches("^[a-zA-Z][a-zA-Z0-9_]{4,16}$");
					}
					
					public static boolean isPassword(String password)
					{
						return password.matches("^[\\da-zA-Z`=\\[\\];',./~!@#$%^&*()_+|{}:\"<>?]{4,16}$");
					}
					
					public static Boolean pwdStreng(String password){
						 boolean flag = false;
						  
						  /** 必须包含数字 */
						  String digit = "\\S*[0-9]+\\S*";
						  /** 必须包含英文字符 */
						  String letter = "\\S*[a-zA-Z]+\\S*";
						  /** 必须包含特殊字符 */
						  String especialChar = "\\S*\\W+\\S*|\\S*[_]+\\S*";
						  if (Pattern.matches(digit, password)
						    && Pattern.matches(letter, password)
						    && Pattern.matches(especialChar, password)){
						   flag = true;
						  }
						 
						 return flag;
						}
					public static void main(String[] args)
					{
						System.out.println(pwdStreng("#@Sa2"));
						 
					}
}
